package com.fcy.teamwork

import android.accessibilityservice.AccessibilityServiceInfo
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.view.accessibility.AccessibilityManager
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.fcy.teamwork.base.log


class AccessibilityActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_accessiblity)
        /**
         * 开启无障碍服务
         */
        /**
         * 开启无障碍服务
         */
        val button = findViewById<Button>(R.id.Button7)
        button.setOnClickListener { //检测当前无障碍服务已开启的应用列表信息
            val am =
                getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
            val accessibilityServiceList =
                am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK)
            for (info in accessibilityServiceList) {
                log("当前已开启的无障碍服务的信息: " + info.resolveInfo.toString())
            }

            //跳转到系统设置页面，由用户手动点击确认是否开启对应的无障碍服务
            val intent = Intent()
            intent.action = Settings.ACTION_ACCESSIBILITY_SETTINGS
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
        }

    }
}